package cn.ray.springframework.test.bean;

import cn.ray.springframework.beans.BeansException;
import cn.ray.springframework.beans.factory.*;
import cn.ray.springframework.context.ApplicationContext;
import cn.ray.springframework.context.ApplicationContextAware;

public class UserService implements InitializingBean, DisposableBean , BeanNameAware, BeanClassLoaderAware, BeanFactoryAware, ApplicationContextAware {
    private  String uid;
    private UserDao userDao;

    //新加入company和location属性用于测试BeanPostProcessor,BeanFactoryPostProcessor
    private String company;
    private String location;

    private ApplicationContext applicationContext;
    private BeanFactory beanFactory;
    private String beanName;
    private ClassLoader beanClassLoader;

    public UserService(String uid){
         this.uid=uid;
    }
    public UserService(){
    }
    @Override
    public void destroy() throws Exception {
        System.out.println("执行：UserService.destroy");
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        System.out.println("执行：UserService.afterPropertiesSet");
    }

    @Override
    public void setBeanClassLoader(ClassLoader classLoader) {
        this.beanClassLoader=classLoader;
    }

    @Override
    public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
        this.beanFactory=beanFactory;
    }

    @Override
    public void setBeanName(String name) {
        this.beanName=name;
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        this.applicationContext=applicationContext;
    }

    public String queryUserInfo() {
        return userDao.queryUserName(uid) + "," + company + "," + location;
    }

    public String getCompany() {
        return company;
    }

    public void setCompany(String company) {
        this.company = company;
    }

    public String getLocation() {
        return location;
    }

    public void setLocation(String location) {
        this.location = location;
    }

    public ApplicationContext getApplicationContext() {
        return applicationContext;
    }

    public BeanFactory getBeanFactory() {
        return beanFactory;
    }

    public String getBeanName() {
        return beanName;
    }

    public ClassLoader getBeanClassLoader() {
        return beanClassLoader;
    }
}
